package psrc.logic.pages.rede;

import java.sql.SQLException;
import java.util.List;

import psrc.bd.dao.RedeDAO;
import psrc.logic.util.beans.RedeBean;

public class RedeModel {

	public RedeDAO dao = new RedeDAO(null);
	
	public List<RedeBean> getRedesList() throws Exception{
		return dao.seleciona();
	}
	
	public boolean removeRede (List<RedeBean> redes) throws Exception{
		try{
			for (RedeBean bean : redes){
				dao.remove(bean);
			}
		} catch (Exception e) {
			e.printStackTrace();
			throw e;
		}
		return true;
	}

	public boolean insert(RedeBean bean) {
		try {
			dao.adiciona(bean);
		} catch (SQLException e) {
			e.printStackTrace();
		}
		return true;
	}
	
	public void update(RedeBean bean) {
		try {
			dao.edita(bean);
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
	
	public RedeBean getObjectById(String id){
		RedeBean bean = new RedeBean();
		bean.setIdRede(id);
		try {
			return dao.selecionaPorId(bean).get(0);
		} catch (SQLException e) {
			e.printStackTrace();
			return null;
		}
	}
}
